//
//  DetailViewController.swift
//  elarc01
//
//  Created by elarc on 2016/11/7.
//  Copyright © 2016年 elarc. All rights reserved.
//

import Foundation

class DetailViewController: UIViewController {
    
    var backgroundImageView:UIImageView!
    var hamburgerView:HamburgerView!
    
    var menuItem: NSDictionary? {
        didSet {
            if let newMenuItem = menuItem {
                view.backgroundColor = UIColor.randomColor()
                backgroundImageView?.image = UIImage(named: newMenuItem["bigImage"] as! String)
            }
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.randomColor()
        
        let tapGestureRecognizer = UITapGestureRecognizer(target: self,action: #selector(DetailViewController.hamburgerViewTapped))
        hamburgerView = HamburgerView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
        hamburgerView.addGestureRecognizer(tapGestureRecognizer)
        
        navigationController?.navigationBar.clipsToBounds = true
        navigationItem.leftBarButtonItem = UIBarButtonItem(customView: hamburgerView)
        
        configSubViews()
    }
    
    func configSubViews() {
        backgroundImageView = UIImageView(frame: CGRectMake(0, 0, ScreenWidth, ScreenHeight))
        self.view.addSubview(backgroundImageView)
        
    }
    
    func hamburgerViewTapped() -> Void {
        
        let navigationController = parentViewController as! UINavigationController
        let containerViewController = navigationController.parentViewController as! ContainerViewController
        containerViewController.hideOrShowMenu(!containerViewController.showingMenu, animated: true)
    }
}